
<?php
header("Content-type: text/html; charset=utf-8");
$ip = $_SERVER["REMOTE_ADDR"];

$dbms='mysql';     //数据库类型
$host='localhost'; //数据库主机名
$dbName='ruiqu';    //使用的数据库
$user='root';      //数据库连接用户名
$pass='Sama!@#123';          //对应的密码
$dsn="$dbms:host=$host;dbname=$dbName";


try {
    $dbh = new PDO($dsn, $user, $pass); //初始化一个PDO对象
    //向数据库插入访问者ip

    $start_time = strtotime(date('Y-m-d 00:00:00'));
    $end_time = strtotime(date('Y-m-d 00:00:00',strtotime("+1 day")));
//筛选出今天的所有ip
    $sql = "SELECT * FROM guest WHERE access_time >= $start_time && access_time <$end_time GROUP BY ip_address";
    $count = $dbh->query($sql);
    $i = 0;
    foreach ($count as $k => $v) {
        $i++;
    }
    echo 'uv:'.$i;
//筛选出今天所有的点击量
    $sql = "SELECT * FROM guest WHERE access_time >= $start_time && access_time <$end_time";
    $count = $dbh->query($sql);
    $i = 0;
    foreach ($count as $k => $v) {
        $i++;
    }
    echo '<br/>pv:'.$i;
    $dbh = null;
} catch (PDOException $e) {
    die ("Error!: " . $e->getMessage() . "<br/>");
}


?>
